package com.znufe.exam.utility;

import com.znufe.exam.base.BaseConstant;
import io.swagger.models.auth.In;

/**
 * @ProjectName: 08-uexam
 * @Package: com.znufe.exam.utility
 * @ClassName: VoteUtil
 * @Author: bot
 * @Description: 答题器处理工具类
 * @Date: 2020/6/17 15:44
 * @Version: 1.0
 */
public class VoteUtil {

    /**
     * 答题器获取答案的方式是生成一个十进制short值value，
     * 通过把value值转换成二进制后，来判断用户的选项，例如：12，转换成二进制是1100，那么对应的答案是D、C（按照ABCD倒序来处理）
     * A80答题器最多支持6位二进制，对应的答案就是A、B、C、D、E、F
     * @param value
     * @return
     */
    public static String intToAnswer(short value){
        String binary = Integer.toBinaryString(value);
        binary = StringUtil.reverseString(binary);
        char[] chr = binary.toCharArray();
        StringBuffer sb = new StringBuffer();
        for(int i=0 ; i< chr.length; i++){
           if(chr[i] == 49 && i==0){
               sb.append("A,");
           }else if(chr[i] == 49 && i==1){
               sb.append("B,");
           }else if(chr[i] == 49 && i==2){
               sb.append("C,");
           }else if(chr[i] == 49 && i==3){
               sb.append("D,");
           }else if(chr[i] == 49 && i==4){
               sb.append("E,");
           }else if(chr[i] == 49 && i==5){
               sb.append("F,");
           }

        }
        if(sb.indexOf(",") != -1){
            return sb.substring(0,sb.length()-1);
        }else{
            return "";
        }
    }




    public static void main (String[] args){
        System.out.println(intToAnswer((short)15));
    }


}
